#ifndef __MV_MAP_INTERFACE
#define __MV_MAP_INTERFACE

PRECLASS( MVMapSource );

#define MIF_SELECT   0x00000001UL
#define MIF_IGNORE   0x00000002UL

STRUCT( MVMapInfo )
  DWORD         Flags;
  PMVMapSource  Owner;
  GBounds       Bounds;
  MVBounds      ExactBounds;
  PathString    File;
  PathString    Caption;

  MVMapInfo( void );
  MVMapInfo( const MVMapInfo& p );
};

CLASS( MVMapLoader )
  protected:
   double G2P_matrix[ 6 ],
          P2G_matrix[ 6 ];

  protected:
    virtual bool         NormalizeLoad( void );
    virtual PMVMapLoader CreateClone( void ) = 0;

  public:
    MVMapLoader( PMVModule own );
    virtual ~MVMapLoader();

    virtual bool         Load( CONSTSTR fnm ) = 0;
    virtual bool         FullLoad( CONSTSTR fnm ) = 0;
    virtual PMVMapLoader Clone( void );
    virtual void         Clear( void );

    virtual void         G2RasterPoint( GCoord_t x, GCoord_t y, MyPoint& p );
    virtual void         Raster2GPoint( int x, int y, GPoint& gp );

    CONSTSTR              LoaderName;  //Name of loader registered in system
    PMVModule             Owner;
    MyRefArray<GMapPoint> MapPoints;   //Conatins LL<->XY points
    PathString            MapFile,     //Loaded file name
                          Caption,     //Map caption
                          ImageFile;   //Name of used image file
    int                   Datum;       //Map datum
    Coordinate_Type       CoordSys;    //Map coord sys
    MVProjectionInfo      Projection;  //OPT Map projection
    GBounds               MapBounds;   //Full map bounds
    MVBounds              Bounds;      //Exact raster map bounds defined by user
};

//---------------------------------------------------------------------------
typedef bool __fastcall (__closure *MVMapEnumEvent)( PMVMapInfo mi, LPVOID Ptr );

CLASS( MVMapSource )
  public:
    PMVModule      Owner;
    bool           Refreshed;
    PMVMapLoader   Loader;

  public:
    MVMapSource( PMVModule Owner );
    virtual ~MVMapSource();

    virtual void  RefreshMapList( MVMapEnumEvent cb, LPVOID Ptr ) = 0;
    virtual bool  LoadMap( PMVMapInfo mi ) = 0;
};

CLASSBASE( MVFilesMapSource, public MVMapSource )
    MVMapEnumEvent UserCB;
    LPVOID         UserPtr;

    bool ScanDirsINT( CONSTSTR path );  // UserCB and UserPtr must be set before call

  public:
    MVFilesMapSource( PMVModule Owner );

    /* Ret:
         false on error or if user callback ret false
    */
    bool ScanDirs( CONSTSTR path, MVMapEnumEvent cb, LPVOID Ptr );

    PathString Pattern;
};

//---------------------------------------------------------------------------
#define MVRF_HAS_FULLBITMAP  0x00000001UL
#define MVRF_HAS_BITS        0x00000002UL

STRUCT( MVRasterInfo )
  DWORD         Flags;    //MVRF_xx

//MVRF_HAS_BITS
  int           Width;
  int           Height;
  LPBITMAPINFO  BitmapInfo;
  LPVOID        Bits;

  void GV_DECLSPEC (__closure *GetCurrentPositionRect)( const MyRect& Container, MyRect& Position );
  void GV_DECLSPEC (__closure *ScrollTo)( int ImageWidth, int ImageHeight, int offx, int offy );
};

//---------------------------------------------------------------------------
#define MV_MAIN_VERSION    MK_ID( 'M', 'N', 1, 0 )
#define MV_PLUGIN_LIB_ID   MK_ID( 'L', 'B', 1, 0 )

enum ScrenScrollTypes {
  sstScreenCenter
};

LOCALSTRUCT( MVMapInterface )
  PMVModule Owner;

  virtual void       GV_DECLSPEC Close( void ) = 0;

  virtual void       GV_DECLSPEC GetGeoArea( GBounds& r ) = 0;      // Geo, full bounds
  virtual bool       GV_DECLSPEC ContainsPoint( const GPoint& p ) = 0;  // geo

  // Zooms
  virtual void       GV_DECLSPEC FillZoomLevels( TStrings *Strings, int& defz ) = 0;
  virtual int        GV_DECLSPEC GetZoomLevel( const AnsiString& s ) = 0;
  virtual int        GV_DECLSPEC ValidateZoom( int v ) = 0;
  virtual int        GV_DECLSPEC IncZoom( int Zoom ) = 0;
  virtual int        GV_DECLSPEC DecZoom( int Zoom ) = 0;
  virtual void       GV_DECLSPEC ZoomChanged( int z ) = 0;

  //Info
  virtual void       GV_DECLSPEC GetMapCaption( AnsiString& str ) = 0;

  // Geo <-> Raster conversion
  virtual void       GV_DECLSPEC Screen2G( int x, int y, GPoint& gp ) = 0;
  virtual void       GV_DECLSPEC G2Screen( GCoord_t x, GCoord_t y, MyPoint& sp ) = 0;

  //Paint
  virtual void       GV_DECLSPEC Paint( TCanvas *dc, MyRect& dr ) = 0;

  //Scroll
  virtual void       GV_DECLSPEC ScrollTo( int x, int y ) = 0;             //Move to scroll bars pos
  virtual void       GV_DECLSPEC ScrollToViewPoint( int x, int y, ScrenScrollTypes type ) = 0;    //Move to screen point

  //Raster\Preview
  virtual bool       GV_DECLSPEC GetPreviewInfo( PMVRasterInfo p ) = 0;

  //Loaded map
  virtual PMVMapLoader GV_DECLSPEC GetLoader( void ) = 0;
};

#endif